<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>支付成功</title>
    <link rel="stylesheet" href="styles.css" />
  </head>
  <body>
    <div class="container">
      <div class="success-container">
        <svg
          class="checkmark"
          xmlns="http://www.w3.org/2000/svg"
          viewBox="0 0 52 52"
        >
          <circle class="checkmark-circle" cx="26" cy="26" r="25" fill="none" />
          <path
            class="checkmark-check"
            fill="none"
            d="M14.1 27.2l7.1 7.2 16.7-16.8"
          />
        </svg>

        <h1>支付成功!</h1>
        <p>您的支付已经成功处理。</p>

        <div id="order-summary" class="order-summary hidden">
          <h3>订单信息</h3>
          <p id="order-id"></p>
          <p id="payment-id"></p>
        </div>

        <div class="button-container">
          <a href="/" id="home-btn" class="btn">返回首页</a>
          <a href="#" id="return-btn" class="btn secondary-btn hidden"
            >返回商家</a
          >
        </div>
      </div>
    </div>

    <script>
      document.addEventListener('DOMContentLoaded', function () {
        // 从URL获取支付和订单信息
        const urlParams = new URLSearchParams(window.location.search);
        const paymentIntent = urlParams.get('payment_intent');
        const paymentIntentClientSecret = urlParams.get(
          'payment_intent_client_secret'
        );
        const orderId = urlParams.get('orderId');
        const returnUrl =
          urlParams.get('returnUrl') || sessionStorage.getItem('returnUrl');

        // 显示支付和订单信息
        const orderSummary = document.getElementById('order-summary');
        const orderIdElem = document.getElementById('order-id');
        const paymentIdElem = document.getElementById('payment-id');

        if (orderId || paymentIntent) {
          orderSummary.classList.remove('hidden');

          if (orderId) {
            orderIdElem.textContent = `订单号: ${orderId}`;
          }

          if (paymentIntent) {
            paymentIdElem.textContent = `支付ID: ${paymentIntent}`;
          }
        }

        // 处理返回按钮
        const returnBtn = document.getElementById('return-btn');

        if (returnUrl) {
          // 显示返回商家按钮
          returnBtn.classList.remove('hidden');

          // 添加订单ID到返回URL
          if (orderId) {
            const separator = returnUrl.includes('?') ? '&' : '?';
            returnBtn.href = `${returnUrl}${separator}orderId=${orderId}&status=success`;
          } else {
            returnBtn.href = returnUrl;
          }

          // 5秒后自动返回
          setTimeout(() => {
            window.location.href = returnBtn.href;
          }, 5000);
        }
      });
    </script>

    <style>
      .success-container {
        text-align: center;
        padding: 40px 0;
      }

      .checkmark {
        width: 80px;
        height: 80px;
        margin: 0 auto 30px;
        display: block;
      }

      .checkmark-circle {
        stroke-dasharray: 166;
        stroke-dashoffset: 166;
        stroke-width: 2;
        stroke-miterlimit: 10;
        stroke: #15803d;
        fill: none;
        animation: stroke 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards;
      }

      .checkmark-check {
        transform-origin: 50% 50%;
        stroke-dasharray: 48;
        stroke-dashoffset: 48;
        stroke-width: 3;
        stroke: #15803d;
        animation: stroke 0.3s cubic-bezier(0.65, 0, 0.45, 1) 0.8s forwards;
      }

      @keyframes stroke {
        100% {
          stroke-dashoffset: 0;
        }
      }

      .success-container p {
        margin-bottom: 20px;
        font-size: 18px;
        color: #4a5568;
      }

      .order-summary {
        background-color: #f8fafc;
        border-radius: 8px;
        padding: 20px;
        margin: 25px auto;
        max-width: 400px;
        text-align: left;
      }

      .order-summary h3 {
        margin-bottom: 15px;
        color: #15803d;
        text-align: center;
      }

      .order-summary p {
        margin-bottom: 10px;
        font-size: 16px;
      }

      .button-container {
        display: flex;
        flex-direction: column;
        gap: 10px;
        margin-top: 30px;
        align-items: center;
      }

      .button-container .btn {
        width: 250px;
      }

      @media (max-width: 480px) {
        .success-container {
          padding: 30px 0;
        }

        .checkmark {
          width: 70px;
          height: 70px;
        }

        .button-container .btn {
          width: 100%;
        }
      }
    </style>
  </body>
</html>
